package com.jvm.binary.initialize;

/**
 * ConcurrentInitializeDemo..
 *
 * @author Lizhong
 * @date 2019/3/12
 */


public class ConcurrentInitializeTest {
    static class ConcurrentInitializeDemo {
        static {
            if (true) {
                System.out.println(Thread.currentThread().getId() + "我被初始化了");
                while (true) {

                }
            }

        }
    }

    /**
     * 线程一 执行<clinit>方法 初始化，后进入循环
     * 线程二初始化，阻塞
     *
     * 可用于单例模式的静态内部类
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            System.out.println(Thread.currentThread().getId() + "begin");
            ConcurrentInitializeDemo concurrentInitializeDemo = new ConcurrentInitializeDemo();
            System.out.println(Thread.currentThread().getId() + "over");
        };
        new Thread(runnable).start();
        new Thread(runnable).start();

    }
    /**
     * 13begin
     * 13我被初始化了
     * 14begin
     */
}
